#include "../include/grammaticCDT.h"

int main ()
{
	grammaticADT g;
	g = NewGrammatic("G1");
	
	AddVN(g, "A");
	AddVN(g, "B");
	AddVN(g, "C");	
	
	if (VNcontains(g, "A") == TRUE) {
		printf("ya existe A\n");
	}
	
	if (VNcontains(g, "B") == TRUE) {
		printf("ya existe B\n");
	}
	
	if (VNcontains(g, "C") == TRUE) {
		printf("ya existe C\n");
	}
	
	AddVT(g, "0");
	AddVT(g, "1");
	AddVT(g, "2");
	AddVT(g, "3");
	
	
	if (VTcontains(g, "0") == TRUE) {
		printf("ya existe 0\n");
	}
	
	if (VTcontains(g, "1") == TRUE) {
		printf("ya existe 1\n");
	}
	
	if (VTcontains(g, "2") == TRUE) {
		printf("ya existe 2\n");
	}
	
	if (VTcontains(g, "10") == FALSE) {
		printf("NO existe 10\n");
	}
	
	
//	ShowVNs(g);
//	ShowVTs(g);

	AddInitialSymbol(g, "A");
	
	//char * p [] ={"A > B0", "B > C1", "C > A2", "A > A0"};
	char * p [] ={"A > \\A\\c|\\", "B > 0C", "C > 0", "A > 2B"};
	//char * p [] ={"C > 1A|2B|ABC0123BC", "A > A", "ABC0123BCC > 3B", "ABC0123BCB > 2A"};
	
//	printf("\n\n----------\nGetDirection:\n");

	int i;
	for (i = 0; i < 4; i++)
	{
		printf("production: %s, is to %s\n", p[i], GetDirection(g, p[i]) == LEFT? "left" : "right");
		if (AddProduction(g, p[i]) == ERR)
		{
			printf("no se pudo agregar la prod: %s\n", p[i]);
		}
	}

	printf("El nombre de la gramatica es: %s\n", GetName(g));
	//ShowProductions(g);	
	
	

	char msg [100] = {'\0'};
	if (IsValidGrammatic(g, msg) == TRUE)
	{
		printf("\nGramatica valida!!!!!!!!!!!\n");
	} else
	{
		printf("\nGramatica INVALIDA =(\n");
	}

	printf("mensaje de IsValid: %s\n", msg);
	
	if (IsRegularGrammatic(g) == TRUE)
	{
		printf("\nGramatica regular!!!!!!!!!!!\n");
	} else
	{
		printf("\nGramatica NO REGULAR =(\n");
	}

	if (GrammaticDirection(g) == LEFT)
	{
		printf("\nGramatica a la izq\n");
	} else
	{
		if (GrammaticDirection(g) == RIGHT)
		{
			printf("\nGramatica a la derecha\n");
		} else
		{
			printf("\nError en la direccion de la gramatica\n");
		}
	}
	
	FreeGrammaticADT(g);
	
	return 0;
}

